package com.example.fist.entity;

import javax.persistence.*;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

@Entity
@Table(name = "code", schema = "competition", catalog = "")
public class CodeEntity {
    private int id;
    private String code;
    private int adId;
    private int isvisible;
    private Date createTime;
    private Date useTime;

    public  CodeEntity()  {
        String string = "2000-10-10 10:10:10";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            useTime=sdf.parse(string);
        } catch (ParseException e) {

        }
        isvisible=1;
    }


    @Id
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "code", nullable = false, length = 32)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Basic
    @Column(name = "ad_id", nullable = true, length = 255)
    public int getAdId() {
        return adId;
    }

    public void setAdId(int adId) {
        this.adId = adId;
    }

    @Basic
    @Column(name = "isvisible", nullable = false)
    public int getIsvisible() {
        return isvisible;
    }

    public void setIsvisible(int isvisible) {
        this.isvisible = isvisible;
    }

    @Basic
    @Column(name = "create_time", nullable = false)
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "use_time", nullable = false)
    public Date getUseTime() {
        return useTime;
    }

    public void setUseTime(Date useTime) {
        this.useTime = useTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CodeEntity that = (CodeEntity) o;
        return id == that.id &&
                isvisible == that.isvisible &&
                Objects.equals(code, that.code) &&
                Objects.equals(adId, that.adId) &&
                Objects.equals(createTime, that.createTime) &&
                Objects.equals(useTime, that.useTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, code, adId, isvisible, createTime, useTime);
    }
}
